package com.tour.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 下拉列表常用数据解释器
 * @author Administrator
 *
 */
public class DataListUtils {
    public static void main(String[] args) {
    }

    /**
    **获取登录角色列表
    */
    public static List<Map<String, Object>> getLoginTypeList() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(getMap("1", "admin"));
        list.add(getMap("2", "user"));

        return list;
    }

    /**
    **获取gl_level数据列表
    */
    public static List<Map<String, Object>> getGlLevelList() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(getMap("1", "全部人"));
        list.add(getMap("2", "仅会员"));

        return list;
    }

    public static String getGlLevelNameById(String id) { //根据gl_level的key值获取名称

        List<Map<String, Object>> list = getGlLevelList();

        return getNameById(id, list);
    }

    /**
    **获取user_level数据列表
    */
    public static List<Map<String, Object>> getUserLevelList() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(getMap("1",
                "普通用户"));
        list.add(getMap("2", "会员"));

        return list;
    }

    public static String getUserLevelNameById(String id) { //根据user_level的key值获取名称

        List<Map<String, Object>> list = getUserLevelList();

        return getNameById(id, list);
    }

    /**
    **获取check_status数据列表
    */
    public static List<Map<String, Object>> getCheckStatusList() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(getMap("1", "待审核"));
        list.add(getMap("2",
                "审核通过"));
        list.add(getMap("3",
                "审核不通过"));

        return list;
    }

    public static String getCheckStatusNameById(String id) { //根据check_status的key值获取名称

        List<Map<String, Object>> list = getCheckStatusList();

        return getNameById(id, list);
    }

    /**
    **获取is_read数据列表
    */
    public static List<Map<String, Object>> getIsReadList() {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(getMap("1", "未读"));
        list.add(getMap("2", "已读"));

        return list;
    }

    public static String getIsReadNameById(String id) { //根据is_read的key值获取名称

        List<Map<String, Object>> list = getIsReadList();

        return getNameById(id, list);
    }

    public static String getNameById(String id, List<Map<String, Object>> list) {
        if (id == null) {
            return null;
        }

        if (id.endsWith(",")) {
            id = id.substring(0, id.length() - 1);
        }

        String[] idsplit = id.split(",");
        String rs = "";

        for (String tmp : idsplit) {
            for (Map<String, Object> map : list) {
                if (map.get("id").toString().equals(tmp)) {
                    rs += (map.get("name").toString() + ",");
                }
            }
        }

        if (rs.endsWith(",")) {
            rs = rs.substring(0, rs.length() - 1);
        }

        return rs;
    }

    private static Map<String, Object> getMap(String id, String name) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", id);
        map.put("name", name);

        return map;
    }
}

